var hdLocation = "file:///C:/Users/baoxu/Desktop/hd2/html/"

/*获取地址栏参数*/
$.getUrlParam = function(name){
	var reg= new RegExp("(^|&)"+name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r!=null) return unescape(r[2]); return null;
}

//ul 边界检验
function ulIsBorder(dom,dir,col,total,isChange){

	var index = dom.index();

	switch(dir){

		case "up":

			index = index - col;

			if(index < 0){
				return true;
			}

			break;
		case "down":

			index = index + col;

			if(index > total - 1){
				return true
			}

			break;
		case "left":

			if(index%col == 0){
				return true
			}else{
				index = index - 1;
			}
			
			break;

		case "right":

			if(index%col == col-1){
				return true
			}else{
				index = index + 1;
			}

			break;
	}

	
	if(isChange){
		onSelect("Click",dom.parent().children().eq(index));
	}else{
		dom.parent().children().eq(index).focus();
	}
	
}

//设置焦点
function setFocus(id,order){

	if(!order){

		$("#"+id)[0].tagName == "UL"?$('#'+id+ " li").eq(0).focus():$('#'+id).focus();

	}else{

		$('#'+id+ " li").eq(order).focus()

	}
}
/**/
function onSelect(event,dom,dir){

	var area = dom[0].tagName == "LI"?dom.parent().attr("id"):dom.attr("id");

	window[area](event,dom,dir);

}
/*事件中心*/
function jumpPage() { 

	var dom = $(document.activeElement)

	switch(event.keyCode){
		case 37:
			onSelect("MoveFocus",dom,"left")
			break;
		case 38:
			onSelect("MoveFocus",dom,"up")
			break;
		case 39:
			onSelect("MoveFocus",dom,"right")
			break;
		case 40:
			onSelect("MoveFocus",dom,"down")
			break;
		case 13:
			onSelect("Click",dom)
			break;
		case 66:
			onSelect("Back",dom)
			break;
		case 72:
			onHome()
			break;
		case 27:
			onEnd(dom)
			break;
	}
}

/*home事件*/
function onHome(){

	window.location.href = "file:///C:/Users/baoxu/Desktop/hd2/html/home.html";
}

document.onkeydown=jumpPage;

/*
	跳转到这个页面
*/

function goToThePage(page,firstFocus,order){
	
	$("#"+page).show().siblings().hide();

	setFocus(firstFocus,order);

	homeGlobalData.currentPage = page;

	var index = getNavIndex(homeGlobalData.currentPage)

	$("#nav1y1ul li").eq(index).addClass("heightLine").siblings().removeClass("heightLine");
}

function getNavIndex(currentPage){
	var index;
	switch(currentPage){
		case "t1":
			index = 0;
			break;
		case "t2":
			index = 1;
			break;
		case "t3":
			index = 2;
			break;
		case "t4":
			index = 3;
			break;
	}
	return index;
}

//初始化时间控件
initWatch();

var timer;

function initWatch(){

	var myDate = new Date();

	var date = myDate.getTime();

	changeTime(date)
	
	timer = setInterval(function(){
		date = date + 10000;
		changeTime(date)
	}, 10000);
}

function changeWeek(num){

	var array = ["一","二","三","四","五","六","日"];

	return array[num-1];
}
function changeMon(num){

	if(num < 10){
		return "0" + (num+1);
	}else{
		return num+1;
	}
}
function changeNum(num){

	if(num < 10){
		return "0" + num;
	}else{
		return num;
	}
}
function changeTime(date){

	newDate = new Date(date);
	 //获取当前时间的小时
    var hours = newDate.getHours();//10
    //分钟
    var min = newDate.getMinutes();//36
    //年
    var year = newDate.getFullYear();//2015
    //月    月份的范围是从0~11,所以获得的月份要加1才是当前月
    var mon = newDate.getMonth();//9
    //日
    var day = newDate.getDate();//21
    //星期几
    var week = newDate.getDay();//3

    week = changeWeek(week);

    mon = changeMon(mon);

    day = changeNum(day);

    hours = changeNum(hours);

    min = changeNum(min);

    $("#bx_time").html("<div class='time-left'><p>"+hours+":"+min+"</p></div><div class='time-right'><p>"+mon+"."+day+"</p><p>星期"+week+"</p></div>")
}

